<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('难检匹配列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>字外部ID：</p>
                                <input type="text" name="ziOutId"/>
                            </li>
                            <li>
                                <p>匹配的字：</p>
                                <input type="text" name="zi"/>
                            </li>
                            <li>
                                <p>笔划：</p>
                                <input type="text" name="bihua"/>
                            </li>
                            <li>
                                <p>状态：</p>
                                <select name="status" th:with="type=${@dict.getType('shuowen_mapper_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="dict:shuowenmapper:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="dict:shuowenmapper:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('dict:shuowenmapper:edit')}]];
        var removeFlag = [[${@permission.hasPermi('dict:shuowenmapper:remove')}]];
        var statusDatas = [[${@dict.getType('shuowen_mapper_status')}]];
        var prefix = ctx + "dict/shuowenmapper";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "难检匹配",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'id',
                    visible: false
                },
                {
                    field : 'ziOutId', 
                    title : '字外部ID'
                },
                {
                    field : 'ziImg',
                    title : '原字',
                    formatter: function(value, row, index) {
                        return "<img src='http://img.kkc.cdn.youzhi.net/" + value + "' width=50 height=50/>" ;
                    }
                },
                {
                    field : 'bihua',
                    title : '笔划'
                },
                {
                    field : 'zi', 
                    title : '匹配的字',
                    formatter: function(value, row, index) {
                        return `<font size="6">${value}</font>` ;
                    }
                },
                {
                    field : 'status', 
                    title : '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field : 'diffRate', 
                    title : '匹配度',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="compare(\'' + row.id + '\')"><i class="fa fa-edit"></i>内容比对</a> ');
                        actions.push(`<a class="btn btn-info btn-xs ${editFlag}" href="https://www.zdic.net/hans/${row.zi}" target="_blank"><i class="fa fa-edit"></i>打开汉典</a> `);
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function compare(ziId) {
		    $.modal.openFull("内容对比", url);
		}

		function compare(ziId){
            var title = "学习资料内容整理"
            var url = prefix + "/compare/" + ziId;
		    var width = 800;
            var height = ($(window).height() - 50);
            var index = layer.open({
                type: 2,
                area: [width + 'px', height + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: title,
                content: url,
                btn: ['确认为正确', '关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    $.operate.post(prefix + "/updateStatus", { "id": ziId, "status": 1});
                    layer.close(index)
                },
                btn2: function(index, layero){
                    layer.close(index)
                }
            });
            layer.full(index);
		}

    </script>
</body>
</html>